package com.ihr360.insurance.model.dto.benefits;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ihr360.insurance.model.vo.BenefitTypeVo;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * 公司法定福利（社保公积金）方案
 *
 * */
@Entity
@Table
@DynamicUpdate
public class CompanyBenefitConfig extends AbstractBenefitConfig {

    private static final long serialVersionUID = 7567511007724929063L;

    /** 公司法定福利 */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    private CompanyBenefit companyBenefit;

    /** 法定福利类别(险种) */
    @ManyToOne(fetch = FetchType.LAZY)
    private MandatoryBenefitsType type;

    /** 是否缴纳(不是标注启用禁用状态) */
    private Boolean enabled;

    public CompanyBenefit getCompanyBenefit() {
        return companyBenefit;
    }

    public void setCompanyBenefit(CompanyBenefit companyBenefit) {
        this.companyBenefit = companyBenefit;
    }

    public MandatoryBenefitsType getType() {
        return type;
    }

    public void setType(MandatoryBenefitsType type) {
        this.type = type;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    @JsonIgnore
    public BenefitTypeVo getVoType() {
        if (type == null) {
            return null;
        }
        return new BenefitTypeVo(type.getId(), type.getCode(), type.getName(),
                type.getCategory(), type.getEffectiveAt(), type.getInvalidAt(), type.isEnabled());
    }
}
